package cn.vcjf.weapp.api.setting.service.impl;

import cn.vcjf.weapp.api.setting.entity.OrderOption;
import cn.vcjf.weapp.api.setting.entity.OrderOptionConfig;
import cn.vcjf.weapp.api.setting.mapper.OrderOptionMapper;
import cn.vcjf.weapp.api.setting.service.OrderOptionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Service("orderOptionService")
public class OrderOptionServiceImpl extends ServiceImpl<OrderOptionMapper, OrderOption> implements OrderOptionService {

	private Logger logger = LogManager.getLogger(OrderOptionServiceImpl.class);

	@Override
	public List<OrderOption> getOrderOptions(OrderOptionConfig config) {
		logger.info("初始化--config--开始--");

		List<OrderOption> orderOptions = baseMapper.selectList(new OrderOption().getQueryWrapper());
		for (OrderOption option : orderOptions) {
			if(option.getValue()==null||"0".equals(option.getValue())){
				logger.info("config_key=" + option.getKey() + " ; value=" + option.getValue()+" !!!跳过设置!!!");
			}else {
				if ("auto_Complet_Date".equals(option.getKey())) {
					config.autoCompletDate = option.getIntValue();
				}
				if ("expire_Days".equals(option.getKey())) {
					config.expireDays = option.getIntValue();
				}
				if ("gen_Auto_Failed_Time".equals(option.getKey())) {
					config.genAutoFailedTime = option.getIntValue();
				}
				if ("team_Auto_Failed_Time".equals(option.getKey())) {
					config.teamAutoFailedTime = option.getIntValue();
				}
				if ("cut_Auto_Failed_Time".equals(option.getKey())) {
					config.cutAutoFailedTime = option.getIntValue();
				}
				if ("auto_Complet_Date".equals(option.getKey())) {
					config.autoCompletDate = option.getIntValue();
				}
				if ("profit_scale".equals(option.getKey())) {
					config.profit_scale = option.getIntValue();
				}
				if ("profit_indirect_scale".equals(option.getKey())) {
					config.profit_indirect_scale = option.getIntValue();
				}
				if ("Not_Comment_Order_Expire_Days".equals(option.getKey())) {
					config.NotCommentOrderExpireDays = option.getIntValue();
				}
				if ("cut_active_expire_time".equals(option.getKey())) {
					config.cut_active_expire_time = option.getIntValue();
				}
				if ("team_active_expire_time".equals(option.getKey())) {
					config.team_active_expire_time = option.getIntValue();
				}
			}
			logger.info("config_key=" + option.getKey() + " ; value=" + option.getValue());
		}
		logger.info("初始化--config--完成--");
		return orderOptions;
	}


}
